//
//  UserCenterViewController.m
//  PlayBall
//
//  Created by Edward Zhang on 12-5-8.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddUserCenterViewController.h"
#import "JddCommonFunction.h"
#import "JddViewControllerManager.h"
#import "JddUserProfile.h"
#import "JddDataParser.h"
#import "AppDelegate.h"
#import "AdDetailViewController.h"
#import "JddInitiatePlanViewController.h"
//#import "JddwithdrawCashSecretViewController.h"
//#import "JddRewithdrawCashSecretViewController.h"
#import "UnionListViewController.h"

@interface JddUserCenterViewController ()

@end

@implementation JddUserCenterViewController

@synthesize ListTable;
@synthesize label1;
@synthesize label2;
@synthesize label3;
@synthesize label4;
@synthesize label7;
@synthesize label6;
@synthesize label5;
@synthesize label8;
@synthesize levelImage;
@synthesize button1;
@synthesize button2;
@synthesize button3;

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddUserCenterViewController);

-(IBAction)loginButtonClicked:(id)sender{
    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN
                                                         fromController:self
                                                             withObject:nil
                                                            withObject2:nil];
}
#pragma mark alertView信息判断
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if ([alertView.message isEqualToString:@"您还没有绑定银行卡，请先绑定银行卡"]) {
        if (buttonIndex==0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BIND_CARD_CARD_INFO
                                                                    fromController:self
                                                                        withObject:nil
                                                                       withObject2:nil];
        }
    } else if ([alertView.message isEqualToString:@"您的个人信息不完整，请先完善个人信息"]) {
        if (buttonIndex==0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PROFILE_UPDATE
                                                                    fromController:self
                                                                        withObject:nil
                                                                       withObject2:nil];
        }
    } else if ([alertView.message isEqualToString:@"您的手机号码还未绑定，请先绑定手机号码"]) {
        if (buttonIndex==0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_RE_BIND_MOBILE
                                                                    fromController:self
                                                                        withObject:nil
                                                                       withObject2:nil];
        }
    } else {
        if (buttonIndex==0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN
                                                                    fromController:self
                                                                        withObject:nil
                                                                       withObject2:nil];
        }
    }
}
#pragma mark 提款按钮被点击之后的信息判断
- (void)withdrawButtonClicked {
//    if (loginState == false) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消",nil ];
//        [alert show];
//        
//    } else {
//        if ([[JddUserProfile sharedInstance].IDCard length]<6||[[JddUserProfile sharedInstance].bindMobile length]<6) {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                            message:@"您的个人信息不完整，请先完善个人信息"
//                                                           delegate:self
//                                                  cancelButtonTitle:@"确定"
//                                                  otherButtonTitles:@"取消",nil ];
//            [alert show];
//        } else {
//            if([[JddUserProfile sharedInstance].BankCardNumber length]<6){
//                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                                message:@"您还没有绑定银行卡，请先绑定银行卡"
//                                                               delegate:self
//                                                      cancelButtonTitle:@"确定"
//                                                      otherButtonTitles:@"取消",nil ];
//                [alert show];
//            } else {
                [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_WITHDRAW
                                                                        fromController:self
                                                                            withObject:nil
                                                                           withObject2:nil];
//            }
//        }
//    }
}
//充值
-(IBAction)logoutButtonClicked:(id)sender{
    
//    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
//    appDelegate.moneyNum = @"";
//    appDelegate.redNum = @"";
//    [self rechargeButtonClicked];
    
    if (loginState==false) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
        
    } else {
        
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://azure.dodofs.com/user/Recharge_Mobile.html?userid=%@",[[JddGlobalParameter sharedInstance].dictionary objectForKey:GLOBAL_PARAMETER_USER_ID]]]];
        
        AdDetailViewController *adDetail = [[AdDetailViewController alloc] init];
        adDetail.linkUrl = [NSString stringWithFormat:@"%@%@",BASE_SERVER_HOST_RECHARGE,[[JddGlobalParameter sharedInstance].dictionary objectForKey:GLOBAL_PARAMETER_USER_ID]];
        adDetail.alt = @"充值";
       [self.navigationController pushViewController:adDetail animated:YES];
        
    }

}
//抢红包按钮被点击
- (IBAction)qiangHongBaoBtnClicked:(UIButton *)sender
{
    AdDetailViewController *adDetail = [[AdDetailViewController alloc] init];
    adDetail.linkUrl = @"http://zxapp.jiangduoduo.com/app/go/140801/jc_main.html";
    adDetail.alt = @"抢红包";
    [self.navigationController pushViewController:adDetail animated:YES];
}
//提款按钮被点击
-(IBAction)tiKuanButtonClicked:(id)sender
{
    [self withdrawButtonClicked];
}
//投注记录
- (void)buyHistoryButtonClicked{
    if (loginState==false) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
        
        
    }else {
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BUY_HISTORY
                                                             fromController:self
                                                                 withObject:nil
                                                                withObject2:nil];
        
    }
}
//追号记录
- (void)exbuyHistoryButtonClicked{
    if (loginState==false) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
        
    }else {
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_FOLLOW_NUMBER_HISTORY
                                                             fromController:self
                                                                 withObject:nil
                                                                withObject2:nil];
        
    }
}
//账户明细
- (void)accountDetailButtonClicked{
    if (loginState==false) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
    }else {
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_ACCOUNT_DETAIL
                                                             fromController:self
                                                                 withObject:nil
                                                                withObject2:nil];
        
    }
}
//充值按钮被点击
- (void)rechargeButtonClicked{
    if (loginState==false) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
        
    } else {
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_SELECT_RECHARGE_WAY
                                                             fromController:self
                                                                 withObject:nil
                                                                withObject2:nil];
        
    }
}

////个人信息
//- (void)personalInfoButtonClicked{
//    if (loginState==false) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消",nil ];
//        [alert show];
//        
//    }else {
//        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PROFILE_UPDATE
//                                                             fromController:self
//                                                                 withObject:nil
//                                                                withObject2:nil];
//        
//    }
//}
////绑定手机
//- (void)bindMobileButtonClicked{
//    if (loginState==false) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消",nil ];
//        [alert show];
//        
//    }else {
//        if ([[JddUserProfile sharedInstance].IDCard length]<6) {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                            message:@"您的个人信息不完整，请先完善个人信息"
//                                                           delegate:self
//                                                  cancelButtonTitle:@"确定"
//                                                  otherButtonTitles:@"取消",nil ];
//            [alert show];
//        }else {
//            if ([[JddUserProfile sharedInstance].bindMobile length]>0&&[[JddUserProfile sharedInstance].IsMobileBind intValue] == 1) {
//                [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BIND_MOBILE_SUCCEEDED
//                                                                     fromController:self
//                                                                         withObject:nil
//                                                                        withObject2:nil];
//            }else {
//                [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_RE_BIND_MOBILE
//                                                                     fromController:self
//                                                                         withObject:nil
//                                                                        withObject2:nil];
//            }
//        }
//        
//        
//    }
//}
////绑定银行卡
//- (void)bindCardButtonClicked{
//    if (loginState==false) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消",nil ];
//        [alert show];
//    } else {
//        
//        
//        if ([[JddUserProfile sharedInstance].IDCard length]<6) {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                            message:@"您的个人信息不完整，请先完善个人信息"
//                                                           delegate:self
//                                                  cancelButtonTitle:@"确定"
//                                                  otherButtonTitles:@"取消",nil ];
//            [alert show];
//        }else if (!([[JddUserProfile sharedInstance].bindMobile length]>0&&[[JddUserProfile sharedInstance].IsMobileBind intValue] == 1)){
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                            message:@"您的手机号码还未绑定，请先绑定手机号码"
//                                                           delegate:self
//                                                  cancelButtonTitle:@"确定"
//                                                  otherButtonTitles:@"取消",nil ];
//            [alert show];
//        }else{
//            if ([[JddUserProfile sharedInstance].BankCardNumber length]<6) {
//                [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BIND_CARD_CARD_INFO
//                                                                     fromController:self
//                                                                         withObject:nil
//                                                                        withObject2:nil];
//            }else {
//                [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BIND_CARD_SUCCESSED
//                                                                     fromController:self
//                                                                         withObject:nil
//                                                                        withObject2:nil];
//            }
//        }
//    }
//}
////修改密码
//- (void)modifyPasswordButtonClicked{
//    if (loginState==false) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消",nil ];
//        [alert show];
//        
//    } else {
//        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_MODIFY_PASSWORD
//                                                             fromController:self
//                                                                 withObject:nil
//                                                                withObject2:nil];
//        
//    }
//}
////设置提款密码
//- (void)withdrawCashSecretButtonClicked{
//    if (loginState==false) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消",nil ];
//        [alert show];
//        
//    } else {
//        if ([[JddUserProfile sharedInstance].IsPayPwd intValue] == 1){
//            JddRewithdrawCashSecretViewController *reWithdrawCash = [[JddRewithdrawCashSecretViewController alloc] init];
//            [self.navigationController pushViewController:reWithdrawCash animated:YES];
//        } else {
//            JddwithdrawCashSecretViewController *withdrawCash = [[JddwithdrawCashSecretViewController alloc] init];
//            [self.navigationController pushViewController:withdrawCash animated:YES];
//        }
//    }
//}
//待发起订单
- (void)daiFaqiPlanButtonClicked
{
    if (loginState==false) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
        
    } else {
        JddInitiatePlanViewController *initiatiatePlan = [[JddInitiatePlanViewController alloc] init];
        [self.navigationController pushViewController:initiatiatePlan animated:YES];
        
    }

}
#pragma mark tableView的协议方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0://投注记录
                    [self buyHistoryButtonClicked];
                    break;
                case 1://账户明细
                    [self accountDetailButtonClicked];
                    break;
                case 2://追号记录
                    [self exbuyHistoryButtonClicked];
                    break;
                case 3://待发起订单
                    [self daiFaqiPlanButtonClicked];
                    break;
                default:
                    break;
            }
            break;
        case 1:
            switch (indexPath.row) {
                case 0://安全中心
                    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_USERCENTER_SAFECENTER
                                                                            fromController:self
                                                                                withObject:nil
                                                                               withObject2:nil];
//                case 0://个人信息
//                    [self personalInfoButtonClicked];
//                    break;
//                case 1://绑定手机
//                    [self bindMobileButtonClicked];
//                    break;
//                case 2://绑定银行卡
//                    [self bindCardButtonClicked];
//                    break;
//                case 3://修改密码
//                    [self modifyPasswordButtonClicked];
//                    break;
//                case 4://设置提款密码
//                    [self withdrawCashSecretButtonClicked];
//                    break;
                default:
                    break;
            }
            break;
        case 2:
            switch (indexPath.row) {
                case 0://我的会员
                    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_UNION_MYLIST
                                                                            fromController:self
                                                                               withObject:nil
                                                                               withObject2:nil];
                    break;
                case 1://我的业绩
                    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_UNION_MYYEJI
                                                                            fromController:self
                                                                                withObject:nil
                                                                               withObject2:nil];
                    break;
                case 2://推广链接
                    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_UNION_LIANJIE
                                                                            fromController:self
                                                                                withObject:nil
                                                                               withObject2:nil];
                    
                    break;
                    
                default:
                    break;
            }
            break;
        default:
            break;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
    bgView.layer.borderColor = BORDER_COLOR;
    bgView.layer.borderWidth = 0.5;
    bgView.backgroundColor = [UIColor colorWithRed:250/255.0f green:250/255.0f blue:250/255.0f alpha:1.0];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 30)];
    label.backgroundColor = [UIColor clearColor];
    label.text = [tableHeadTitle objectAtIndex:section];
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor grayColor];
    [bgView addSubview:label];
    return bgView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30.0f;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if([JddUserProfile sharedInstance].IsUnion == true){
        return 3;
    }else{
        return 2;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 57.0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if([JddUserProfile sharedInstance].IsUnion == true){
        switch (section) {
            case 0:
                return 3;//4;
                break;
            case 1:
                return 1;
                break;
            case 2:
                return 3;
                break;
            default:
                return 0;
                break;
        }
    }else{
        switch (section) {
            case 0:
                return 3;//4;
                break;
            case 1:
                return 1;
                break;
            default:
                return 0;
                break;
        }
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JddNewListViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"JddNewListViewCell" owner:self options:nil]lastObject];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.delegate = self;
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    cell.titleLabel.text = @"投注记录";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_touzhujilu.png"];
                    break;
                case 1:
                    cell.titleLabel.text = @"账户明细";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_zhanghumingxi.png"];

                    break;
                case 2:
                    cell.titleLabel.text = @"追号记录";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_zhuihaojilu.png"];

                    break;
                    //modify by rain 先屏蔽待发起订单功能
//                case 3:
//                    cell.titleLabel.text = @"待发起订单";
//                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_daifaqidingdan.png"];
//                    break;
                default:
                    return nil;
                    break;
            }
            
            break;
        case 1:
            switch (indexPath.row) {
                case 0:
                    cell.titleLabel.text = @"完善领奖信息";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_safe_center.png"];
                    break;

//                case 0:
//                
//                    cell.titleLabel.text = @"个人信息";
//                    cell.imageIcon.image = [UIImage imageNamed:@"personal_massige.png"];
//                    break;
//                case 1:
//                    cell.titleLabel.text = @"绑定手机";
//                    cell.imageIcon.image = [UIImage imageNamed:@"bindMobile.png"];
//                    break;
//                case 2:
//                    cell.titleLabel.text = @"绑定银行卡";
//                    cell.imageIcon.image = [UIImage imageNamed:@"bindCard.png"];
//                    break;
//                case 3:
//                    cell.titleLabel.text = @"修改密码";
//                    cell.imageIcon.image = [UIImage imageNamed:@"xiugaiMiMa.png"];
//                    break;
//                case 4:
//                    cell.titleLabel.text = @"设置提款密码";
//                    cell.imageIcon.image = [UIImage imageNamed:@"tiKuanMiMa.png"];
                default:
                    return nil;
                    break;
            }
            break;
        case 2:
            switch (indexPath.row) {
                case 0:
                    cell.titleLabel.text = @"我的会员";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_zhuihaojilu.png"];
                    break;
                case 1:
                    cell.titleLabel.text = @"我的业绩";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_zhuihaojilu.png"];
                    break;
                case 2:
                    cell.titleLabel.text = @"推广链接";
                    cell.imageIcon.image = [UIImage imageNamed:@"jdd_zhuihaojilu.png"];
                    break;
                default:
                    return nil;
                    break;
            }

            break;
        default:
            return cell;
            break;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}

- (void)QueryUserInfoOperationResult:(NSData *)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
        NSString *dictStr = [dict objectForKey:@"Data"];
        NSData *data = [dictStr dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *realDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"realDict = %@",realDict);

        if (![JddDataParser parseUserInfoResult:result]) {
            if ([[[JddViewControllerManager sharedInstance].navigationController topViewController] class] == [JddUserCenterViewController class]) {
//                [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
            }
            
        } else {
            //提前请求参数
            loginState = true;
            [ListTable reloadData];
            if ([JddUserProfile sharedInstance].balance.length > 0)
            {
                self.label7.text = [NSString stringWithFormat:@"%@彩豆", [JddUserProfile sharedInstance].balance];
            } else {
                self.label7.text = @"0彩豆";
            }
            //图片等级
//            NSString *level = [[realDict objectForKey:@"Level"] stringValue];
//            UIImage *levelImg = [JddCommonFunction getImgByLevel:level];
//            //计算等级图标的宽
//            CGFloat wid;
//            if ([level integerValue]%5 == 0) {
//                wid = 5*14;
//            } else {
//                wid = [level integerValue]%5*14;
//            }
//            CGRect frame = self.levelImage.frame;
//            frame.size.width = wid;
//            self.levelImage.frame = frame;
//            self.levelImage.image = levelImg;
        }
    }
    [ListTable reloadData];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)refresh2{
    if([JddCommonFunction isLogin]){
        loginState = true;
        [JddCommonFunction setWaitingViewHidden:NO fromController:self];
        JddQueryUserInfoOperation *operation = [[JddQueryUserInfoOperation alloc] init];
        operation.delegate = self;
        [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    }else {
        loginState = false;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
//    [self.navigationItem setHidesBackButton:YES];

    if (![JddCommonFunction isLogin]) {
        loginState = true;
    }else {
        loginState = false;
    }
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:PAGE_USER_CENTER];
        customLab.textAlignment = NSTextAlignmentCenter;
        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;
    
    tableHeadTitle = [NSArray arrayWithObjects:@"投注管理",@"账号管理",@"推广联盟", nil];
//    self.navigationItem.leftBarButtonItem = nil;
    //self.navigationItem.hidesBackButton = YES;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,0)];
    self.ListTable.tableFooterView = v;
    [self.ListTable setSeparatorColor:SeparatorLineColor];
    if (IOS7) {
        [self.ListTable setSeparatorInset:UIEdgeInsetsZero];
    }
}
-(void)pushMoreView
{
    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_SETTING
                                                            fromController:self
                                                                withObject:nil
                                                               withObject2:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"UserCenter"];
    [self setJddTabBarHidden:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"UserCenter"];
    [MobClick event:@"TAB-UserCenter"];
    
    [self.view setUserInteractionEnabled:YES];
    
    [self setTabBarItemSelect:5];
    //显示tabbar
    [self setJddTabBarHidden:NO];
    
    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
    right.frame = CGRectMake(0, 0, 40, 30);
    [right setTitle:@"更多" forState:UIControlStateNormal];
    right.titleLabel.font = [UIFont systemFontOfSize:15];
    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [right addTarget:self action:@selector(pushMoreView) forControlEvents:UIControlEventTouchUpInside];
    right.titleLabel.font = [UIFont systemFontOfSize:15];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:right];

    if([JddCommonFunction isLogin]){
        loginState = true;
        [JddCommonFunction setWaitingViewHidden:NO fromController:self];
        JddQueryUserInfoOperation *operation = [[JddQueryUserInfoOperation alloc] init];
        operation.delegate = self;
        [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    }else {
        loginState = false;
    }
    if (loginState) {
        self.label1.hidden = YES;
        self.label2.hidden = YES;
        self.label3.hidden = YES;
        self.label4.hidden = NO;
        self.label5.hidden = NO;
        self.label5.text = [JddUserProfile sharedInstance].name;
        self.label6.hidden = NO;
        self.label7.hidden = NO;
//        self.label8.hidden = NO;
        self.levelImage.hidden = NO;

        if ([JddUserProfile sharedInstance].balance.length > 0) {
            self.label7.text = [NSString stringWithFormat:@"%@彩豆", [JddUserProfile sharedInstance].balance];
        }else{
            self.label7.text = @"0彩豆";
        }
        self.button1.hidden = YES;
        self.button2.hidden = NO;
    }else {
        self.label1.hidden = NO;
        self.label2.hidden = NO;
        self.label3.hidden = NO;
        self.label4.hidden = YES;
        self.label5.hidden = YES;
        self.label6.hidden = YES;
        self.label7.hidden = YES;
//        self.label8.hidden = YES;
        self.levelImage.hidden = YES;
        self.button1.hidden = NO;
        self.button2.hidden = YES;
    }
    [ListTable reloadData];
}

@end
